package retrofit2.harmony.util.rx;

import com.uber.autodispose.AutoDispose;
import com.uber.autodispose.AutoDisposeConverter;
import ohos.aafwk.ability.Lifecycle;
import retrofit2.harmony.autodispose.HarmonyLifecycleScopeProvider;

/**
 * 配合uber的AutoDispose封装一下
 */
public class RxLifecycleUtil {
    private RxLifecycleUtil() {
    }

    /**
     * Rx绑定生命周期，在onStop
     *
     * @param lifecycle 生命周期对象
     */
    public static <T> AutoDisposeConverter<T> bindLifecycle(Lifecycle lifecycle) {
        return AutoDispose.autoDisposable(HarmonyLifecycleScopeProvider.from(lifecycle, Lifecycle.Event.ON_STOP));
    }
}